package com.api.shopapi.mapper;

import com.api.shopapi.entity.CashierCartBusiness;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
@Mapper
public interface CashierCartBusinessMapper {

    @Insert("insert into cashier_cart_business " +
            "(" +
            "CashierCartBusinessCode," +
            "CashierCartCode," +
            "Price," +
            "BusinessCode," +
            "UserCode," +
            "GoodsType," +
            "Type," +
            "GuaDanRen," +
            "CreateTime" +
            ")" +
            "values" +
            "(" +
            "#{cashierCartBusiness.CashierCartBusinessCode}," +
            "#{cashierCartBusiness.CashierCartCode}," +
            "#{cashierCartBusiness.Price}," +
            "#{cashierCartBusiness.BusinessCode}," +
            "#{cashierCartBusiness.UserCode}," +
            "#{cashierCartBusiness.GoodsType}," +
            "#{cashierCartBusiness.Type}," +
            "#{cashierCartBusiness.GuaDanRen}," +
            "#{cashierCartBusiness.CreateTime}" +
            ")")
    public int insert(@Param("cashierCartBusiness") CashierCartBusiness cashierCartBusiness);

    @Update("update cashier_cart_business set " +
            "CashierCartCode = #{cashierCartBusiness.CashierCartCode}," +
            "Price=#{cashierCartBusiness.Price}," +
            "BusinessCode=#{cashierCartBusiness.BusinessCode}," +
            "GoodsType=#{cashierCartBusiness.GoodsType}," +
            "Type=#{cashierCartBusiness.Type}," +
            "GuaDanRen=#{cashierCartBusiness.GuaDanRen}," +
            "CreateTime=#{cashierCartBusiness.CreateTime}" +
            " where CashierCartBusinessCode=#{cashierCartBusiness.CashierCartBusinessCode}")
    public int update(@Param("cashierCartBusiness") CashierCartBusiness cashierCartBusiness);

    @Delete("delete from cashier_cart_business where CashierCartBusinessCode=#{cashierCartBusinessCode}")
    public int delete(@Param("cashierCartBusinessCode") String cashierCartBusinessCode);

    @Select("select * from cashier_cart_business")
    public List<CashierCartBusiness> getList();

    @Select("select * from cashier_cart_business where CashierCartBusinessCode=#{cashierCartBusinessCode} limit 1")
    public CashierCartBusiness getByCashierCartBusinessCode(@Param("cashierCartBusinessCode") String cashierCartBusinessCode);


    //购物车中所有的商家订单
    @Select("select * from cashier_cart_business where CashierCartCode=#{cashierCartCode}")
    List<CashierCartBusiness> getListByCashierCartCode(@Param("cashierCartCode") String cashierCartCode);

    //购物车中所有的进行中的商家订单
    @Select("select * from cashier_cart_business where CashierCartCode=#{cashierCartCode} and type='WillSubmit' ")
    List<CashierCartBusiness> getListByCashierCartCodeWillSubmit(@Param("cashierCartCode") String cashierCartCode);


    //进行中的购物车
    @Select("select * from cashier_cart_business where businessCode=#{businessCode}" +
            " and userCode=#{userCode} and type='WillSubmit' limit 1")
    CashierCartBusiness getByBusinessCodeUserCodeWillSubmit(@Param("businessCode") String businessCode,
                                                  @Param("userCode") String userCode);

    //挂起的购物车
    @Select("select * from cashier_cart_business where businessCode=#{businessCode}" +
            " and userCode=#{userCode} and type='WaitSubmit' ")
    List<CashierCartBusiness> getListByBusinessCodeUserCodeWaitSubmit(@Param("businessCode") String businessCode,
                                                            @Param("userCode") String userCode);


}
